using System;
using System.Data;
using System.Web;

using Microsoft.Reporting.WebForms;

namespace BizElements.Web.UI
{
    /// <summary>Form opened by <b>SearchFrm</b> to export/print data. Shares settings data with SearchFrm via sessions.</summary>
    public partial class SearchReportFrm : System.Web.UI.Page
    {
        /// <summary>Initialize Page.UICulture to match culture defined in UserSession.UiCulture.</summary>
        protected override void InitializeCulture()
        {
            this.UICulture = UserSession.UiCulture.Name;
        }

        /// <summary>Loads report definition and displays data contained in Matrix static session property.</summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Matrix != null)
                {
                    this.uiReport.LocalReport.ReportPath = Server.MapPath("SearchResultsMatrix.rdl");
                    this.uiReport.LocalReport.DataSources.Add(new ReportDataSource("matrix", Matrix));
                }

                this.Title = Caption;
            }
        }

        /// <summary>Report data.</summary>
        public static DataTable Matrix
        {
            get { return HttpContext.Current.Session["SearchReportFrm.Matrix"] as DataTable; }
            set { HttpContext.Current.Session["SearchReportFrm.Matrix"] = value; }
        }

        /// <summary>Form title.</summary>
        public static string Caption
        {
            get { return HttpContext.Current.Session["SearchReportFrm.Caption"] as string; }
            set { HttpContext.Current.Session["SearchReportFrm.Caption"] = value; }
        }
    }
}
